<template>
  <el-form>
    <h2>布局设置</h2>
    <el-form-item label="导航条类型">
      <el-radio-group v-model="navbarLayoutType">
        <el-radio label="default" border>default</el-radio>
        <el-radio label="inverse" border>inverse</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="侧边栏皮肤">
      <el-radio-group v-model="sidebarLayoutSkin">
        <el-radio label="light" border>light</el-radio>
        <el-radio label="dark" border>dark</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="颜色和主题">
      <el-radio-group v-model="themeColor">
        <el-radio-button label="蓝绿色"></el-radio-button>
        <el-radio-button label="蓝色"></el-radio-button>
        <el-radio-button label="红色"></el-radio-button>
        <el-radio-button label="黄色"></el-radio-button>
      </el-radio-group>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {};
  },
  beforeCreate() {
    let val;
    switch (localStorage.getItem("theme-color")) {
      case "blue":
        val = "蓝色";
        break;
      case "yellowblue":
        val = "蓝绿色";
        break;
      case "yellow":
        val = "黄色";
        break;
      case "red":
        val = "红色";
        break;
    }
    this.$store.commit("common/updateThemeColor", val);
  },
  methods: {
    themeChange(theme) {
      var str;
      switch (theme) {
        case "蓝绿色":
          str = "yellowblue";
          break;
        case "蓝色":
          str = "blue";
          break;
        case "黄色":
          str = "yellow";
          break;
        case "红色":
          str = "red";
          break;
      }
      localStorage.setItem("theme-color", str);
      this.$router.push({name:'home'})
      location.reload(true);
    }
  },
  computed: {
    navbarLayoutType: {
      get() {
        return this.$store.state.common.navbarLayoutType;
      },
      set(val) {
        this.$store.commit("common/updateNavbarLayoutType", val);
      }
    },
    sidebarLayoutSkin: {
      get() {
        return this.$store.state.common.sidebarLayoutSkin;
      },
      set(val) {
        this.$store.commit("common/updateSidebarLayoutSkin", val);
      }
    },
    themeColor: {
      get() {
        return this.$store.state.common.themeColor;
      },
      set(v) {
        this.$store.commit("common/updateThemeColor", v);
        this.themeChange(v);
      }
    }
  }
};
</script>
<style lang="scss">
div {
  color: #ff4c52;
}
</style>

